//
// Created by fengg on 2020/4/24.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _bin_tree {
    void *data;
    struct _bin_tree  *parent;
    struct _bin_tree  *l_child;
    struct _bin_tree  *r_child;
} BinTree ;

typedef struct _static_entry{
    int data;
    int l_entry;
    int r_entry;
} StaticEntry ;


void Go(BinTree *binTree) {
    if(!binTree)
        return;
    Go(binTree->l_child);
    printf("%d ",*(int*)binTree->data);
    Go(binTree->r_child);
}



void CreatBinTree(void *data,BinTree *parent,BinTree *l_child,BinTree *r_child,BinTree **pTree){

    if(*pTree == NULL){
        *pTree = malloc(sizeof(BinTree));
    }
    (*pTree)->data    = data;
    (*pTree)->parent  = parent;
    (*pTree)->l_child = l_child;
    (*pTree)->r_child = r_child;


}

int main(){
    int temp_i,temp_l,temp_r;
    int index=0,max_len=0;
    StaticEntry raw_data[100];
    BinTree *binTreeArr[100] = {0x0};
    BinTree *temp_tree = NULL;
    scanf("%d %d %d",&temp_i,&temp_l,&temp_r);
    while (temp_i || temp_l || temp_r){
        raw_data[index].data = temp_i;
        raw_data[index].l_entry = temp_l;
        raw_data[index++].r_entry = temp_r;
        scanf("%d %d %d",&temp_i,&temp_l,&temp_r);
    }
    max_len = index;
    while (--index >=0){
        binTreeArr[index] = calloc(1,sizeof(BinTree));
        binTreeArr[index]->data = &raw_data[index].data;

    }
    while (++index < max_len){
        binTreeArr[index]->r_child = raw_data[index].r_entry  ?
                                     binTreeArr[raw_data[index].r_entry]:NULL;
        binTreeArr[index]->l_child = raw_data[index].l_entry  ?
                                     binTreeArr[raw_data[index].l_entry]:NULL;
    }
    Go(binTreeArr[0]);
    return 0;
}